home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Sample Code / Snippets / Toolbox / SICN LDEF / mylistdef.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-12  |  2.8 KB  |  116 lines  |  [TEXT/MPS ]

  1. /*    SICN LDEF
  2.  
  3.     ©1991 Apple Computer, Inc.
  4.     written by Steven Falkenburg 5/23/91
  5.     This LDEF displays small icons to the left of text in a list.
  6.     
  7.     The small icon is stored in the first 16 bytes of each cell.
  8. */
  9.  
  10. #include <Types.h>
  11. #include <QuickDraw.h>
  12. #include <Lists.h>
  13. #include <Memory.h>
  14.  
  15. /* constants for spacing */
  16.  
  17. #define kLeftOffset    2
  18. #define kTopOffset    0
  19. #define kIconSpace    2
  20.  
  21. /* prototypes */
  22.  
  23. void DrawSICN(Ptr theSICN,short left,short top,GrafPtr drawPort);
  24.  
  25. /* main LDEF entry point */
  26.  
  27. pascal void    theLDEF(short lMessage,Boolean lSelect,Rect *lRect,Cell lCell,
  28.                 short lDataOffset,short lDataLen,ListHandle lHandle)
  29. {
  30.     FontInfo fontInfo;                        /* font information (ascent/descent/etc) */
  31.     ListPtr listPtr;                        /* pointer to store dereferenced list */
  32.     SignedByte hStateList,hStateCells;        /* state variables for HGetState/SetState */
  33.     Ptr cellData;                            /* points to start of cell data for list */
  34.     Ptr theSICN;                            /* points to SICN to be drawn */
  35.     short leftDraw,topDraw;                    /* left/top offsets from topleft of cell */
  36.         
  37.     /* lock and dereference list mgr handles */
  38.     
  39.     hStateList = HGetState((Handle)lHandle);
  40.     HLock((Handle)lHandle);
  41.     listPtr = *lHandle;
  42.     hStateCells = HGetState(listPtr->cells);
  43.     HLock(listPtr->cells);
  44.     cellData = *(listPtr->cells);
  45.     
  46.     switch (lMessage) {
  47.       case lInitMsg:
  48.           /* we don't need any initialization */
  49.           break;
  50.  
  51.       case lDrawMsg:
  52.         EraseRect(lRect);
  53.         
  54.           if (lDataLen > 0) {
  55.           
  56.               /* determine starting point for drawing */
  57.               
  58.               leftDraw =    lRect->left+listPtr->indent.h+kLeftOffset;
  59.               topDraw =    lRect->top+listPtr->indent.v+kTopOffset;
  60.               
  61.               /* plot SICN (first 32 bytes) */
  62.               
  63.               if (lDataLen > 32) {
  64.                   theSICN = cellData+lDataOffset;
  65.                   DrawSICN(theSICN,leftDraw,topDraw,listPtr->port);
  66.                   lDataOffset += 32;
  67.                   lDataLen -= 32;
  68.               }
  69.               leftDraw += 16+kIconSpace;
  70.               
  71.               /* plot text (offset 32 bytes onward) */
  72.               
  73.             GetFontInfo(&fontInfo);
  74.             MoveTo(leftDraw,topDraw+fontInfo.ascent);
  75.             
  76.             /* set condensed mode if necessary (if the text doesn't fit otherwise) */
  77.             
  78.             TextFace(0);
  79.             if (TextWidth(cellData,lDataOffset,lDataLen) > (lRect->right - leftDraw))
  80.                 TextFace(condense);
  81.  
  82.             DrawText(cellData,lDataOffset,lDataLen);
  83.           }
  84.  
  85.         if (!lSelect)
  86.               break;
  87.  
  88.       case lHiliteMsg:
  89.           InvertRect(lRect);
  90.           break;
  91.  
  92.       case lCloseMsg:
  93.           break;
  94.     }
  95.     
  96.     HSetState((Handle)listPtr->cells,hStateCells);
  97.     HSetState((Handle)lHandle,hStateList);
  98. }
  99.  
  100.  
  101. /* this procedure draws a small icon using CopyBits */
  102.  
  103. void DrawSICN(Ptr theSICN,short left,short top,GrafPtr drawPort)
  104. {
  105.     BitMap iconMap;
  106.     Rect destRect;
  107.  
  108.     iconMap.baseAddr = theSICN;
  109.     iconMap.rowBytes = 2;
  110.     SetRect(&iconMap.bounds,0,0,16,16);
  111.     SetRect(&destRect,0,0,16,16);
  112.     OffsetRect(&destRect,left,top);
  113.     CopyBits(&iconMap,&drawPort->portBits,&iconMap.bounds,&destRect,
  114.             srcCopy,nil);
  115. }
  116.